import 'package:json_annotation/json_annotation.dart';

part 'git_repo.g.dart';

@JsonSerializable()
class GitRepo {
  final int id;
  // 仓库名称
  final String name;
  // 仓库路径 查看详情需要用到
  final String path;
  // 仓库描述
  final String? description;
  // 克隆地址HTTPS
  final String html_url;
  // 克隆地址SSH
  final String ssh_url;
  // 默认分支
  final String default_branch;
  // 语言
  final String? language;
  // issue数量
  final int open_issues_count;
  // 是否私有
  final bool private;
  final String project_creator;
  // 是否公开
  final bool public;
  final bool has_issues;
  final String created_at;

  // 最近一次代码推送时间
  final String pushed_at;

  // 是否 star
  final bool stared;

  // star数量
  final int stargazers_count;

  // 更新时间
  final String updated_at;
  final bool watched;
  final int watchers_count;
  final bool fork;
  final int forks_count;
  final String? forks_url;
  final Owner owner;

  GitRepo({
    required this.id,
    required this.name,
    required this.path,
    this.description,// 可选字段
    required this.html_url,
    required this.ssh_url,
    required this.default_branch,
    this.language,
    required this.open_issues_count,
    required this.private,
    required this.project_creator,
    required this.public,
    required this.has_issues,
    required this.created_at,
    required this.pushed_at,
    required this.stared,
    required this.stargazers_count,
    required this.updated_at,
    required this.watched,
    required this.watchers_count,
    required this.fork,
    required this.forks_count,
    this.forks_url,
    required this.owner,
  });

  factory GitRepo.fromJson(Map<String, dynamic> json) =>
      _$GitRepoFromJson(json);

  Map<String, dynamic> toJson() => _$GitRepoToJson(this);
}

@JsonSerializable()
class Owner {
  final int id;
  final String login;
  final String name;
  final String avatar_url;
  final String url;
  final String html_url;
  final String remark;
  final String followers_url;
  final String following_url;
  final String gists_url;
  final String starred_url;
  final String subscriptions_url;
  final String organizations_url;
  final String repos_url;
  final String events_url;
  final String received_events_url;
  final String type;

  Owner({
    required this.id,
    required this.login,
    required this.name,
    required this.avatar_url,
    required this.url,
    required this.html_url,
    required this.remark,
    required this.followers_url,
    required this.following_url,
    required this.gists_url,
    required this.starred_url,
    required this.subscriptions_url,
    required this.organizations_url,
    required this.repos_url,
    required this.events_url,
    required this.received_events_url,
    required this.type,
  });
  factory Owner.fromJson(Map<String, dynamic> json) => _$OwnerFromJson(json);
  Map<String, dynamic> toJson() => _$OwnerToJson(this);
}
